package org.ru.mse10.cvis.web.helper;

import java.util.ArrayList;
import java.util.List;

import org.ru.mse10.cvis.entity.codelists.CodelistValue;
import org.ru.mse10.cvis.entity.misc.TranslatedValue;
import org.ru.mse10.cvis.web.model.initializer.DefaultInstanceInitializer;

/**
 * The Class LanguageModelTableHelper.
 * 
 * @author mse10slb
 */
public class LanguageModelTableHelper extends ModelTableHelper<CodelistValue> {

	/** The translated values. */
	private List<TranslatedValue> translatedValues = new ArrayList<TranslatedValue>();

	/**
	 * Instantiates a new language model table helper.
	 */
	public LanguageModelTableHelper() {
		super(
				new DefaultInstanceInitializer<CodelistValue>(
						CodelistValue.class));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.ru.mse10.cvis.web.helper.ModelTableHelper#initNewRow()
	 */
	@Override
	public void initNewRow() {
		super.initNewRow();
		translatedValues.clear();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.ru.mse10.cvis.web.helper.ModelTableHelper#storeNewRow()
	 */
	@Override
	public void storeNewRow() {
		for (TranslatedValue value : translatedValues) {
			getCurrentRow().getModelObject().getTranslatedValues()
					.put(value.getLanguageKey(), value);
		}
	}

	/**
	 * Gets the translated values.
	 * 
	 * @return the translated values
	 */
	public List<TranslatedValue> getTranslatedValues() {
		return translatedValues;
	}

	/**
	 * Sets the translated values.
	 * 
	 * @param translatedValues
	 *            the new translated values
	 */
	public void setTranslatedValues(List<TranslatedValue> translatedValues) {
		this.translatedValues = translatedValues;
	}
}
